<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet" />
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}" />
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}" />
    <script th:src="@{/erp/assets/js/jquery.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
</head>
<body>
<input type="hidden" th:value="${list.postId}" />
<form>
<!--编辑区域分配图层-->
<div class="edit_menber" id="edit_menber_style">
    <ul class=" page-content">

        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>员工编号：</label>
            <div class="formControls ">
                <input type="text" class="input-text" th:value="${list.staffId}" placeholder=""  name="staffId" readonly="readonly">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red">*</span>部门职位：</label>
            <div class="formControls ">
                <select  style="margin-left:10px;" id="deptName" name="deptId">
                    <option value="" selected disabled>--选择部门--</option>
                    <option th:each="dept:${session.dept}"th:value="${dept.id}" th:selected="${dept.id}==${list.deptId}">
                        [[${dept.deptName}]]
                    </option>
                </select>
                <select style="margin-left:10px;" id="postName" name="postId">
                    <option value="" selected disabled>--选择职位--</option>
                </select>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>工资科目：</label>
            <div class="formControls" th:each="aa: ${salaryList}">
                <lable style="width:140px;"><input type="checkbox" name="ids" value="1" style="width:16px;height:16px;margin-left:10px;" th:checked="${aa.salaryBase} eq 1" /><span class="1b1" style="margin-left:2px;">基本工资</span></lable>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="2" style="width:16px;height:16px;margin-left:10px;" th:checked="${aa.salaryMerit} eq 2 "/>
                    <span class="1b1" style="margin-left:2px;">绩效工资</span></lable><br>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="3"style="width:16px;height:16px;margin-left:10px;" th:checked="${aa.salaryWork} eq 3"/>
                    <span class="1b1" style="margin-left:2px;" >加班工资</span></lable>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="4" style="width:16px;height:16px;margin-left:10px;" th:checked="${aa.salarySubsidy} eq 4"/>
                    <span class="1b1" style="margin-left:2px;" >补助资金</span></lable><br>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="5" style="width:16px;height:16px;margin-left:10px;" th:checked="${aa.salaryFive} eq 5"/>
                    <span class="1b1" style="margin-left:2px;" >五险一金</span></lable>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>联系电话：</label>
            <div class="formControls ">
                <input type="text" class="input-text" th:value="${list.staffTel}" placeholder="" id="tel" name="staffTel" onblur="isTel()">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>入职时间：</label>
            <div class="formControls "><span th:text="${#dates.format(list.staffEntry,'yyyy-MM-dd')}"  style="margin-left:10px;"></span>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>员工状态：</label>
            <div class="formControls ">
                <select style="margin-left:10px;" name="staffStatus">
                    <option th:each="lists:${session.status}"th:value="${lists.staffStatus}" th:selected="${lists.staffStatus}==${list.staffStatus}">
                        [[${lists.staffWork}]]
                    </option>
                </select>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>帐号状态：</label>
            <div class="formControls">
                <span  style="margin-left:10px;" th:text="${list.numberId eq '1'} ? '已启用':'已停用' "></span>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label">员工成绩：</label>
            <div class="formControls">
                <textarea name="staffScore" rows="" class="textarea" th:text="${list.staffScore}" placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true"></textarea>
                <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
            </div>
        </div>
        <div class="">
            <div class="" style=" text-align:center">
                <input class="btn btn-primary radius" id="tijiao" type="submit" value="保存">
              <input class="btn btn-primary radius" id="tijiao1" type="button" value="取消">
            </div>
        </div>

    </ul>
</div>
</form>
</body>
<script>

    function isTel(){
        var s =$("#tel").val();
        if(!(/^1[3456789]\d{9}$/.test(s))){

            layer.msg("手机号码有误，请重填", {icon: 2});
            return false;
        }
    }

    function isStaffName(){
        var staffName = $("#staffUsername").val();
        $.ajax({
            type:"get",
            url:"/staff/isStaffName",
            data:{"staffName":staffName,"flag":"1"},
            success:function (res) {
                if (res.rs) {

                } else {
                    layer.msg("员工账号已存在", {icon: 2});
                }
            }
        })
    }

    $(function () {
//部门下拉框改变事件
        $("#deptName").change(function () {
            var dept = $("#deptName").val();
            if(dept==null){
                return;
            }
            $.ajax({
                cache:true,
                type:"get",
                url:"/staff/postZhi",
                data:{"deptId":dept},
                success:function (data) {
                    console.log(data);
                    var postId = $("#postName").empty();
                    for(var i=0;i<data.length;i++){
                        postId.append("<option value='"+data[i]["postId"]+"'>"+data[i]["postName"]+"</option>");
                    }
                }
            })
        })

        $("#deptName").trigger('change')


        $('#tijiao').on('click', function () {
            var chk_value =[];
            $('input[name="ids"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数
                chk_value.push($(this).val());//将选中的值添加到数组chk_value中
            });


            var staffUsername = $("#staffUsername").val();
            var staffPwd = $("#staffPwd").val();
            var staffName = $("#staffName").val();
            var staffId = $("#staffId").val();
            var deptName = $("#deptName").val();
            var tel = $("#tel").val();
            var start = $("#start").val();
            if(staffUsername == ""){
                layer.msg("登陆账号不能为空", {icon: 2});
            }else if(staffPwd == ""){
                layer.msg("初始密码不能为空", {icon: 2});
            }else if(staffName == ""){
                layer.msg("员工姓名不能为空", {icon: 2});
            }else if(staffId == ""){
                layer.msg("员工编号不能为空", {icon: 2});

            }else if(deptName == null){
                layer.msg("部门职位不能为空", {icon: 2});
                return false;
            }else if(tel ==""){
                layer.msg("联系电话不能为空", {icon: 2});

            }else if(start ==""){
                layer.msg("入职时间不能为空", {icon: 2});

            }else{

            var data = $('form').serialize();


            $.post('/staff/upd?status='+chk_value,data, function (res) {
                if (res.rs) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.msg(res.msg, {icon: 1});
                    $('#likeSelect',parent.window.document).click();
                    parent.layer.close(index); //再执行关闭

                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            });

            }
            return false;
        });
        $('#tijiao1').on('click', function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
    });
</script>
</html>